
#ifndef RTDEBASEDEFINE_H
#define RTDEBASEDEFINE_H


#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <pthread.h>
#include "stdbool.h"


#define DEBUG_PRINT 0




typedef enum{
    RTDE_Control_Interface_Port               = 2297,
    RTDE_IO_Control_Interface_Port            = 2295,
    RTDE_Receive_Interface_Port               = 2299,
}RTDE_PORT;

typedef struct 
{
    int sock_io_control;
    int sock_receive;
    int sock_control;
}Socket_fd_t;



#define RTDE_SOCK_BUF_MAX                   (20*1024)
#define RTDE_MAX_VARNAME                    (100)
#define RTDE_MAX_METHOD_NAME                (100)
#define RTDE_MAX_OUTPUT_VAR                 (2000)
#define RTDE_MAX_INPUT_VAR                  (1000)
#define RTDE_MAX_METHODS                    (3000)

#define RTDE_RECV_STATE_IDLE                (0)
#define RTDE_RECV_STATE_RUN                 (1)
#define RTDE_RECV_STATE_PAUSE               (2)

typedef enum {
    RTDE_REQUEST_PROTOCOL_VERSION        = 86,//	V	
    RTDE_GET_CONTROL_VERSION             = 118,	//v	
    RTDE_DATA_PACKAGE                    = 85,//	U	
    RTDE_METHOD_PACKAGE	                 = 109,//	m	service methods
    RTDE_CONTROL_PACKAGE_SETUP_OUTPUTS   = 79,//	O	setup output recipe
    RTDE_CONTROL_PACKAGE_SETUP_INPUTS    = 73,//	I	setup input recipe
    RTDE_CONTROL_PACKAGE_START           = 83,//	S	
    RTDE_CONTROL_PACKAGE_PAUSE           = 80,//	P	
    RTDE_GET_CONTROL_OUTPUTS             = 82,//	R	get controller output variables
    RTDE_GET_CONTROL_INPUTS              = 114,//	r	get controller input variables
    RTDE_GET_CONTROL_METHODS             = 77,//	M	get controller support methods
}RTDE_PACKAGE_TYPE;

typedef enum RtdeVarType
{
    INVALIDT                     = 0,
    BOOL                         = 1,
    UINT8                        = 2,
    UINT16                       = 3,
    UINT32                       = 4,
    UINT64                       = 5,
    INT8                         = 6,
    INT16                        = 7,
    INT32                        = 8,
    INT64                        = 9,
    FLOAT                        = 10,
    DOUBLE                       = 11,
    VECTOR3D                     = 12,
    VECTOR6D                     = 13,
    VECTOR3F                     = 14,
    VECTOR6F                     = 15,
    VECTOR6INT32                 = 16,
    VECTOR6UINT32                = 17,
    STRING                       = 18,
    DATA_TYPE_MAX
}RtdeVarType;


typedef struct {
    RtdeVarType data_type;
    uint8_t type_len;
    uint8_t data[100]; 
}rtde_data_t;

typedef struct {
    RtdeVarType param_type;
    uint8_t param_len;
    uint8_t* param_data; 
}rtde_param_t;

typedef struct {
    uint16_t method_index;
    uint8_t method_param_num;
    rtde_param_t *method_param_param;
}rtde_method_param_t;


/* RTDE Variable Property */
typedef struct {
    char varname[RTDE_MAX_VARNAME];
    uint32_t varcode;
    uint8_t datatype;
    uint8_t byteslen;
    uint8_t used;               // used for input var recipes
    uint8_t reserved;
}rtde_varlist_t;

typedef struct {
    char methodname[RTDE_MAX_METHOD_NAME];
    uint16_t methodcode;
    uint16_t reserved;
}rtde_method_list_t;



typedef struct RtdeVarInfo
{
    uint8_t varNameLen;
    uint8_t varName[RTDE_MAX_VARNAME];   //非'\0'结尾
    int32_t varId; //变量id
    RtdeVarType varType;
}RtdeVarInfo;

typedef struct RtdeVar
{
    // int32 result; //异常码 0-suceess 非0-错误码
    uint8_t number;  //多少个变量 【0-10】
    RtdeVarInfo rtdeVarInfo[10];
}RtdeVar;


typedef struct RtdeFuncInfo
{
     uint8_t funcNameLen;
     uint8_t funcName[RTDE_MAX_METHOD_NAME];   //非'\0'结尾
     int16_t funcId; //变量id  
}RtdeFuncInfo;

typedef struct RtdeFunc
{
    // int32_t result; //异常码 0-suceess 非0-错误码
    uint8_t number;  //多少个变量 【0-10】
    RtdeFuncInfo rtdeFuncInfo[10];
}RtdeFunc;




#endif
